package com.anolesoft.twelveFactory.planManagement.dto;


import com.anolesoft.twelveFactory.planManagement.entity.PlanEmployee;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.sql.Date;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class PlanissuedDto  implements Comparable<PlanissuedDto>{
    private String objuid;
    private String jhbj;
    private String jx;
  @JsonFormat(pattern = "yyyy-MM",timezone="GMT+8")
    private Date khrq;
    private String pt;
    private String ld;
    private String jflj;
    private String th;
    private Integer dj;
    private String djs;
    private String nbfg;
    private String gylx;
    private String fz;
    private Integer jxmlkc;
    private Integer mlkczs;
    private Integer jxbcpkc;
    private Integer bcpkczs;
    private String jd;
    private String dtx;
   @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date gskhrq;
    private String dykhpjc;
    private Integer lsjhsl;
   @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date jhwc;
   @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date sjwc;
    private String wx;
    private String jfzt;
    private String swgx;
    private String sfczq;
    private String jflx;
    private String ljlx;
    private String bz;
    private String bcsm;
    private String fzr;
    private String xl;
    private String wg;
    private String wcxz;
    private String cp;
    private String gj;
    private String sb;
    private String jszl;
    private String yorn;
    private String zt;
    private String jfcj;
    private String jscj;
    private String jfsx;
    private String jhzt;
    private Integer pageNo; //页数
    private Integer pageSize; //每页显示条数


    //    核对
    private String jhdj;
    private String jxmllj;
    private String jxbcplj;
    private String wthz;
   @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date ldkhrq;
   @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date jfrq;
   @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date wcrq;
    private String tlsl;
   @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date gdwjrq;
    private String wxcj;
    private String cpkc;
    private String yxzw;
    private String yjqk;


    //核对修改
    private String jsjd;
    private String gjjd;
    private String sbjd;

    // 确认
    private String ljxh;
    private String dtxbj;
    private String cg;
    private String qg;
    private String xg;
    private String mg;
    private String dqgx;
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date jhkg;


    private String fth;
    private String xh;
    private String clph; //材料牌号
    private String clgg; //材料规格
    private String dzjdh;//锻铸件代号
    private String clphclgg; //材料牌号+材料规格

    private List<PlanEmployee> employees; //员工集合
    private String ygxm;//员工姓名
    private List<PlanissuedDto> children; //序号
    private String code;
    private String objuidgyjh;
    private String wyzd;
    @Override // 字符串比较
    public int compareTo(PlanissuedDto o) {
        return o.getTh().compareTo(this.th);
    }
    //构造函数
    public PlanissuedDto(String th, String fth) {
        super();
        this.th = th;
        this.fth = fth;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) //1.判断this与obj是否引用同一个对象
            return true;
        if (obj == null) //2.判断obj是否为null
            return false;
        if (getClass() != obj.getClass()) //3.判断this与obj是否属于同一类
            return false;
        PlanissuedDto other = (PlanissuedDto) obj; //4.将obj转换为相应的类类型

        //5.判断域（域）是否相同，基本数据类型使用==，对象域使用equals方法比较
        if (th == null) {
            if (other.th != null)
                return false;
        } else if (!th.equals(other.th))
            return false;
        return true;
    }


    //hashCode() 方法用于返回字符串的哈希码。
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((th == null) ? 0 : th.hashCode());
        return result;
    }

    public  static void setChildren(List<PlanissuedDto> all,PlanissuedDto plan){
        String th = plan.getTh();
        List<PlanissuedDto> children = all.stream().filter(p -> {
            return p.getFth()!=null && th.equals(p.getTh());
        }).collect(Collectors.toList());
        if (children.size() > 0) {
            children.stream().forEach(c -> {
                PlanissuedDto.setChildren(all, c);
            });

            plan.setChildren(children);
        }
    }

    public PlanissuedDto() {
        super();
    }

    public static void setChildrenCode(List<PlanissuedDto> list, String pCode) {
        for (int i = 0; i < list.size(); i++) {
            String code = pCode + "."+(i+1);
            list.get(i).setCode(code);
            List<PlanissuedDto> children = list.get(i).getChildren();
            if(children != null && !children.isEmpty()) {
                PlanissuedDto.setChildrenCode(children, code);
            }
        }
    }
}
